/**
 * @file field
 * @author fanxueliang@qq.com
 */

import type {UploadSpecItem, ImageUploaderField} from '../interface';
import {getBasicField} from '../util';

export function createImageUploaderField(spec: UploadSpecItem, showIndex: number, path: string) {
    const extensions = [];
    if (spec?.extraAttr?.extensions) {
        extensions.push(...spec.extraAttr.extensions);
    }
    if (spec.rules) {
        spec.rules.imageUrl = true;
    } else {
        spec.rules = {
            imageUrl: true
        };
    }
    const basicField = getBasicField(spec, path, showIndex);
    const multiple = spec?.extraAttr?.multiple || false;
    return {
        ...basicField,
        extensions,
        type: 'STRING',
        isLeaf: true,
        spec,
        component: 'Uploader',
        multiple
    } as ImageUploaderField;
}
